home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / inventor / www / workarounds / TexturePrint.C < prev   
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.8 KB  |  112 lines

  1. //
  2. // This is a patch for the Inventor 2.0 SoTexture2 node, which will
  3. // use incorrect display lists when rendering to another gl rendering
  4. // context (most commonly done when rendering to an
  5. // SoOffScreenRenderer for printing).
  6. //
  7. //
  8. // To apply this patch, compile this file into a .o and then link
  9. // the .o before -lInventor.  The linker may give a warning.
  10. // This is normal and expected.
  11. //
  12.  
  13. #include <Inventor/actions/SoGLRenderAction.h>
  14. #include <Inventor/elements/SoGLCacheContextElement.h>
  15. #include <Inventor/elements/SoGLTextureBlendColorElement.h>
  16. #include <Inventor/elements/SoGLTextureEnabledElement.h>
  17. #include <Inventor/elements/SoGLTextureImageElement.h>
  18. #include <Inventor/elements/SoGLTextureModelElement.h>
  19. #include <Inventor/elements/SoGLTextureQualityElement.h>
  20. #include <Inventor/elements/SoGLTextureWrapSElement.h>
  21. #include <Inventor/elements/SoGLTextureWrapTElement.h>
  22. #include <Inventor/elements/SoTextureBlendColorElement.h>
  23. #include <Inventor/elements/SoTextureModelElement.h>
  24. #include <Inventor/elements/SoTextureWrapSElement.h>
  25. #include <Inventor/elements/SoTextureWrapTElement.h>
  26. #include <Inventor/errors/SoDebugError.h>
  27. #include <Inventor/nodes/SoTexture2.h>
  28.  
  29. ////////////////////////////////////////////////////////////////////////
  30. //
  31. // Description:
  32. //    Performs GL rendering on a texture node.
  33. //
  34. // Use: extender
  35.  
  36. void
  37. SoTexture2::GLRender(SoGLRenderAction *action)
  38. //
  39. ////////////////////////////////////////////////////////////////////////
  40. {
  41.     SoState *state = action->getState();
  42.  
  43.     if (! wrapS.isIgnored())
  44.     SoTextureWrapSElement::set(state, this,
  45.         (SoTextureWrapSElement::Wrap)wrapS.getValue());
  46.  
  47.     if (! wrapT.isIgnored())
  48.     SoTextureWrapTElement::set(state, this,
  49.         (SoTextureWrapTElement::Wrap)wrapT.getValue());
  50.  
  51.     if (! model.isIgnored())
  52.     SoTextureModelElement::set(state, this,
  53.         (SoTextureModelElement::Model)model.getValue());
  54.  
  55.     if (! blendColor.isIgnored())
  56.     SoTextureBlendColorElement::set(state, this,
  57.         blendColor.getValue());
  58.     if (! image.isIgnored()) {
  59.     SbVec2s size;
  60.     int nc;
  61.     const unsigned char *bytes = image.getValue(size, nc);
  62.  
  63.     // Check for special cases of 1/2 component texture and model
  64.     // DECAL or 3/4 component texture and model BLEND; print out
  65.     // errors in these cases:
  66.     
  67.     SoTextureModelElement::Model m =
  68.         SoTextureModelElement::get(state);
  69.     if (nc < 3 && m == SoTextureModelElement::DECAL) {
  70. #ifdef DEBUG
  71.         SoDebugError::post("SoTexture2::GLRender",
  72.         "Texture model is DECAL, but texture image"
  73.         " has only %d components (must be 3 or 4).  "
  74.         "Use imgcopy to convert the image.", nc);
  75. #endif        
  76.     }
  77.     else if (nc > 2 && m == SoTextureModelElement::BLEND) {
  78. #ifdef DEBUG
  79.         SoDebugError::post("SoTexture2::GLRender",
  80.         "Texture model is BLEND, but texture image"
  81.         " has %d components (must be 1 or 2).  "
  82.         "Use imgcopy to convert the image.", nc);
  83. #endif        
  84.     } else {
  85.         // This is kind of weird-- the element builds and uses the
  86.         // display list (which is why we pass it in and assign
  87.         // it) because it sends the GL calls, and needs to know
  88.         // the list if the state is popped.  But this node must
  89.         // manage storage and deletion of the display list, since
  90.         // the list must go away if the node is deleted or the
  91.         // image is changed.
  92.  
  93.         // See if renderList is valid (in the right context):
  94.         int context = SoGLCacheContextElement::get(state);
  95.         if (renderList != -1 && listContext == context) {
  96.         SoGLTextureImageElement::set(
  97.             state, this, size, nc, bytes, renderList);
  98.         }
  99.         else {  // Not valid, try to build
  100.         // Free up old list, if necessary:
  101.         if (renderList != -1) {
  102.             SoGLCacheContextElement::freeList(state, listContext,
  103.                               renderList, 1);
  104.         }
  105.         renderList = SoGLTextureImageElement::set(
  106.             state, this, size, nc, bytes, -1);
  107.         listContext = context;
  108.         }
  109.     }
  110.     }
  111. }
  112.